using System;
using NBusiness.Data;
using System.Data.Common;

namespace Example.Business
{
    public partial class LogLevel
    {
        public override void Initialize()
        {
            this.Fetching += new EventHandler<FetchEventArgs>(FetchingByLevel);
        }

        #region FetchByLevel
        public static LogLevel FetchByLevel(string level)
        {
            return new LogLevel(new FetchByLevelCriteria(level));
        }

        private class FetchByLevelCriteria : CriteriaBase
        {
            private string _level;
            public string Level
            {
                get { return _level; }
            }
            public FetchByLevelCriteria(string level)
                : base()
            {
                _level = level;
            }
        }

        protected virtual void FetchingByLevel(object sender, FetchEventArgs e)
        {
            if (e.Criteria is FetchByLevelCriteria)
            {
                Settings.Instance.Database.Fetch(
                    e.Connection,
                    "LogLevelFetchByLevel",
                    e.Criteria,
                    Load,
                    new Parameter("@Level", ((FetchByLevelCriteria)e.Criteria).Level));
            }
        }
        #endregion
    }
}